package com.sky.controller;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Employee;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类相关接口
 */
@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "分类相关接口")
public class CategoryController {

    @Autowired
    private CategoryService CategoryService;


    /**
     * 分类分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    @ApiOperation("分类分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("分类分页查询{}", categoryPageQueryDTO);
        PageResult pageResult =CategoryService.pageQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 新增分类
     * @param categoryDTO
     * @return
     */
    @ApiOperation("新增分类")
    @PostMapping
    public Result<String> save(@RequestBody CategoryDTO categoryDTO){
        log.info("新增分类{}", categoryDTO);
        CategoryService.save(categoryDTO);
        return Result.success();
    }


    /**
     *启停菜品
     * @param status
     * @param id
     * @return
     */
    @ApiOperation("启停菜品")
    @PostMapping("/status/{status}")
    public Result startOrstop(@PathVariable Integer status,Long id){
        log.info("启停菜品id:{},status:{}",id,status);
        CategoryService.starOrStop(status,id);

        return Result.success();
    }

    /**
     * 修改分类
     * @param categoryDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改分类")
    public Result update(@RequestBody CategoryDTO categoryDTO){
        log.info("修改分类{}", categoryDTO);
        CategoryService.update(categoryDTO);
        return Result.success();
    }

    /**
     * 根据id删除分类
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除分类")
    public Result delete(Long id){
        log.info("删除分类，id:{}",id);
        CategoryService.delete(id);
        return Result.success();
    }

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result<List<Category>> list(Integer type){
        List<Category> list = CategoryService.list(type);
        return Result.success(list);
    }

    /**
     * 根据id查询分类
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询分类")
    public Result<String> getById(@PathVariable Long id){
        log.info("根据id查询分类{}",id);
        String categoryName = CategoryService.getById(id);
        return Result.success(categoryName);
    }

    /**
     * 查询所有分类名称
     */
    @GetMapping("/listAll")
    @ApiOperation("查询所有分类名称")
    public Result<List<String>> listAll(){
        log.info("查询所有分类名称");
        List<String> list = CategoryService.listAll();
        return Result.success(list);
    }

}
